package com.ego.service.impl;

import com.ego.dubbo.service.ManagerDubboService;
import com.ego.pojo.Manager;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    /**
     * 消费zookeeper中 ManagerDubboServiceImpl 对象
     */
    @DubboReference
    private ManagerDubboService managerDubboService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {


        Manager manager = managerDubboService.selectManagerByUsername(username);


        //Manager manager = userMapper.selectManagerByUsername(username);


        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();



        return new User(username,manager.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList("不涉及权限"));
    }


}

